<div ng-controller="contractPayinfoCtrl">
    <div class="table-header clearfix ng-scope">
        <span class="fl lh30 f14">{{contractBaseInfo.contract_code}}</span>
    </div>

    <form class="form-horizontal" name="contractPayinfoForm">

        <div class="mt20 ml25 clearfix" ng-if="!areaRole">
            <div>
                <div id="fileupload" class="fileinput-button btn" >
                    <span class="f13">上传附件</span>
                    <input type="file" name="file" accept=".xls,.xlsx,.doc,.docx,.pdf,.msg" >
                </div>
                <div class="c-red f13" style="clear:both;display: none;" id="fileupload_tip">上传中……</div>
                <div class="c-red f13" style="clear:both;display: none" id="fileupload_error">上传失败</div>
                <input type="hidden" id="fileupload_url" value="{{contractFiles}}"/>

                <div>
                    <div style="height: 28px;display: inline-block;margin-right: 20px"
                         ng-repeat="file in contractFiles" ng-if="file.__type != 'delete'">
                        <a target="_blank" href="{{file.attachement_path}}">{{file.attachement_name}}</a>
                        <a class="glyphicon glyphicon-trash" title="删除附件" href="javascript: void(0)"
                           ng-click="delAttachment(file,$index)" ></a>
                    </div>
                </div>

            </div>
        </div>


        <div class="mt20 clearfix ng-scope ml25">
            <span class="fl lh30 f14">交付业绩</span>
        </div>
        <div class="table-wrap mt10 ml25" style="min-height: 200px;overflow: visible">

            <table width="100%" class="valign-t">
                <thead>
                <tr>
                    <th style="width: 35px;">序号</th>
                    <th ng-repeat="attribute_name in attribute_name_text" style="width: 33px;" class="align-m">{{attribute_name}}</th>
                    <th style="width: 110px;" class="align-m">交付业绩金额</th>
                    <th style="width: 120px;" class="align-m">交付业绩归属时间</th>
                    <th style="width: 200px;">交付归属信息</th>
                    <!--<th style="width: 100px;" >交付时间</th>-->
                    <th style="width: 200px;" class="align-m">备注</th>
                    <th class="align-m">操作</th>
                </tr>
                </thead>
                <tbody>
                <tr ng-repeat="record in contractPayinfo" ng-if="record.__type != 'delete'"
                    style="line-height: 35px;">
                    <td><p ng-bind="$index + 1"></p></td>

                    <td ng-repeat="text in attribute_name_text" class="align-m">
                        <input type="checkbox" ng-disabled="(record.editMode || 0) == 0" ng-model="record.attribute_name[$index]" ng-true-value='"true"' ng-false-value='"false"'  >
                    </td>

                    <td class="align-r">
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="record.dely_amount | number:2"></p>

                        <p ng-if="(record.editMode || 0) != 0">
                            <input type="text" ng-model="record.dely_amount" class="form-control"
                                   placeholder="交付业绩金额">
                        </p>
                    </td>
                    <td class="align-m">
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="record.dely_on|strdate:'yyyy-MM-dd'"></p>

                        <p ng-if="(record.editMode || 0) != 0">
                            <input type="text" name="dely_on" class="form-control"
                                   ng-model="record.dely_on" ui-date
                                   format="yyyy-MM-dd" placeholder="交付业绩归属时间">
                        </p>

                    </td>
                    <td style="line-height: 27px;">
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="'交付人：'+record.belong_name"></p>

                        <p ng-if="(record.editMode || 0) != 0" style="position:relative;">交付人：
                            <input name="belong_by" select2 ng-model="record.belong_by" style="position: absolute;top: 0;width: 130px;right: 0;"
                                   select2-model="record.ddl2BelongBy" data="record"
                                   config="ddlConfigBelongBy" type="text" placeholder="交付归属人"
                                   class="form-control idBelongBy1">
                        </p>
                        <p ng-bind="'归属部门：'+record.department_name"></p>
                        <p ng-bind="'归属区域：'+record.area_name"></p>
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="'交付时间：'+(record.dely_belong_on | strdate:'yyyy-MM-dd')"></p>
                        <p style="position: relative;" ng-if="(record.editMode || 0) != 0">交付时间：
                            <input type="text" style="position: absolute;top: 0;width: 130px;right: 0;" name="dely_belong_on" class="form-control"
                                   ng-model="record.dely_belong_on" ui-date
                                   format="yyyy-MM-dd" placeholder="交付时间">
                        </p>
                    </td>
                    <td>
                        <p ng-if="(record.editMode || 0) == 0" ng-bind="record.dely_mark" style="position:relative;"></p>
                        <p>
                        <textarea ng-if="(record.editMode || 0) != 0"  class="form-control" rows="3" ng-model="record.dely_mark" ng-maxlength="500" ></textarea>
                        <span role="alert"
                              ng-show="(contractPayinfoForm.$submitted || contractPayinfoForm.dely_mark.$touched) && contractPayinfoForm.dely_mark.$error.maxlength"
                              class="error ng-hide c-red lh30">备注信息不能超过500个字符</span>
                        </p>
                    </td>

                    <td class="align-m">
                        <div row-toolbar min-buttons-show="3"
                             ng-if="contractBaseInfo.is_cancelled == 0 && userAuthList.indexOf('0001') !== -1">
                            <a ng-if="(record.editMode || 0)  == 0" href="javascript:void(0)"
                               title="拆分交付信息"
                               ng-click="addSignAchievement(contractPayinfo,record)">拆分</a>
                            <a ng-if="(record.editMode || 0)  == 0" href="javascript:void(0)"
                               title="修改交付信息"
                               ng-click="editSignAchievement(record, $index,contractPayinfo)">修改</a>
                            <a ng-if="(record.editMode || 0)  == 0 && contractPayinfo.length>1"
                               ng-click="delSignAchievement(record,$index,contractPayinfo)"
                               href="javascript:void(0)"
                               title="删除交付信息">删除</a>

                            <a ng-if="(record.editMode || 0)  != 0" href="javascript:void(0)"
                               title="保存交付信息"
                               ng-click="saveSignAchievement(record)">确定</a>
                            <a ng-if="(record.editMode || 0)  != 0" href="javascript:void(0)"
                               title="取消修改交付信息"
                               ng-click="cancelSignAchievement(record, $index,contractPayinfo)">取消</a>
                        </div>
                    </td>
                </tr>
                </tbody>
            </table>
            <div class="no-data" ng-if="contractPayinfo.length == 0"><span>暂无数据</span></div>
        </div>
        <div class="mt10 ml25">
            <span class="pl10">说明：交付业绩金额(<em class="b">{{ (paymentAmount ||0) |number:2}}</em>元)
            = 已确定业绩（<em class="b">{{contractPayinfo|sumPayAmount|number:2}}</em>元） + 待确定业绩（<em
                        class="b c-red">{{contractPayinfo|remainPayAmount:paymentAmount|number:2}}</em>元）
            </span>
        </div>




        <div class="form-group" ng-if="!areaRole">
            <div class="ml35 mt15">
                <button type="button"
                        ng-click="contractPayinfoForm.$valid && save()"
                        class="btn btn-default"
                        ng-if="contractBaseInfo.is_cancelled == 0 && userAuthList.indexOf('0001') !== -1">
                    保存
                </button>
            </div>
        </div>
    </form>
</div>